package com.deyou.util;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.deyou.AppManager;
import com.deyou.R;

/**
 * Created by yangyuancheng on 2017/5/25.
 */

public class AndroidUtils {

    /***
     * @param activity 当前activity
     * @param cls      跳转的activity
     * @param bundle   传值
     * @param isFinish 是否关闭当前activity
     */
    public static void startNextActivity(Activity activity, Class<?> cls, Bundle bundle, boolean isFinish) {
        if (null != activity)
            AppManager.getAppManager().addActivity(activity);
        Intent intent = new Intent(activity, cls);
        if (bundle != null)
            intent.putExtras(bundle);
        activity.startActivity(intent);
        if (isFinish)
            activity.finish();
        activity.overridePendingTransition(R.anim.c_next_h_show, android.R.anim.fade_out);
        // activity.overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
    }

    /**
     * 带返回请求进行Activity跳转
     *
     * @param activity    当前Activity
     * @param cls         目标Activity
     * @param bundle      传值
     * @param requestCode Activity请求码
     */
    public static void startNextActivityForResult(Activity activity, Class<?> cls, Bundle bundle, int requestCode) {
        if (null != activity)
            AppManager.getAppManager().addActivity(activity);
        Intent intent = new Intent(activity, cls);
        if (bundle != null)
            intent.putExtras(bundle);
        activity.startActivityForResult(intent, requestCode);
        activity.overridePendingTransition(R.anim.c_next_h_show, android.R.anim.fade_out);
        // activity.overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
    }

    /***
     * Activity跳转入口-无跳转动画
     * @param activity 当前activity
     * @param cls      跳转的activity
     * @param bundle   传值
     * @param isFinish 是否关闭当前activity
     */
    public static void startNextActivityNoTranAnim(Activity activity, Class<?> cls, Bundle bundle, boolean isFinish) {
        if (null != activity)
            AppManager.getAppManager().addActivity(activity);
        Intent intent = new Intent(activity, cls);
        if (bundle != null)
            intent.putExtras(bundle);
        activity.startActivity(intent);
        if (isFinish)
            activity.finish();
        // activity.overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
    }

    /**
     * 带返回请求进行Activity跳转-无动画
     *
     * @param activity    当前Activity
     * @param cls         目标Activity
     * @param bundle      传值
     * @param requestCode Activity请求码
     */
    public static void startNextActivityForResultNoTranAnim(Activity activity, Class<?> cls, Bundle bundle, int requestCode) {
        if (null != activity)
            AppManager.getAppManager().addActivity(activity);
        Intent intent = new Intent(activity, cls);
        if (bundle != null)
            intent.putExtras(bundle);
        activity.startActivityForResult(intent, requestCode);
        // activity.overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
    }
}
